package com.scl.cloud.config;

import com.scl.cloud.filter.PreRequestLogFilter;
import com.scl.cloud.route.CustomServiceRouteMapper;
import com.scl.cloud.route.ZuulRouteLocator;
import com.scl.cloud.filter.UrlRedirectFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import org.springframework.cloud.netflix.zuul.filters.discovery.PatternServiceRouteMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author shengchenglong
 * @version 1.0
 * @since 17/9/11 13:52 JDK 1.8
 */
@Configuration
public class ZuulConfig {

    @Autowired
    private ZuulProperties zuulProperties;
    @Autowired
    private ServerProperties server;

    @Bean
    public ZuulRouteLocator routeLocator() {
        ZuulRouteLocator routeLocator = new ZuulRouteLocator(this.server.getServlet().getServletPrefix(), this.zuulProperties);
        return routeLocator;
    }


//    @Bean
//    public PatternServiceRouteMapper patternServiceRouteMapper() {
//        return new PatternServiceRouteMapper("(?<name>^.+)-(?<version>v.+$)", "${version}/${name}");
//    }
//
//    @Bean
//    public CustomServiceRouteMapper customServiceRouteMapper() {
//        return new CustomServiceRouteMapper();
//    }

    @Bean
    public PreRequestLogFilter preRequestLogFilter() {
        return new PreRequestLogFilter();
    }


    @Bean
    public UrlRedirectFilter urlRedirectFilter() {
        return new UrlRedirectFilter();
    }
}
